package com.medicine.manage.block.service.impl;

import com.medicine.manage.block.EncryptUtils;
import com.medicine.manage.block.entity.WeBaseResult;
import com.medicine.manage.block.service.AbstractBlockService;
import com.medicine.manage.block.service.IBlockProcessService;
import com.medicine.manage.block.service.IBlockService;
import com.medicine.manage.domain.Packaging;
import org.springframework.stereotype.Service;

@Service("blockProcessPackageService")
public class BlockProcessPackageServiceImpl extends AbstractBlockService<Packaging> implements IBlockProcessService<Packaging> {

    private final String INSERT_ONE_METHOD = "insertPackage";
    private final String SELECT_ONE_METHOD = "selectPackage";
    private final String UPDATE_METHOD = "updatePackage";

    @Override
    public WeBaseResult insertProcessObj(Packaging packaging, Long deptId, Long optionUserId) {
        return this.insertOne(packaging, deptId, optionUserId, INSERT_ONE_METHOD);
    }

    @Override
    public WeBaseResult selectProcessObj(Long orderId, Long packageId, Long deptId, Long optionUserId) {
        return this.selectOne(orderId, packageId, deptId, optionUserId, SELECT_ONE_METHOD);
    }

    @Override
    public WeBaseResult updateProcessObj(Packaging packaging, Long deptId, Long optionUserId) {
        return this.update(packaging.getOrderId(),  packaging, deptId, optionUserId, UPDATE_METHOD);
    }

    @Override
    protected String createParam(Packaging o, Long optionUserId) {
        StringBuffer param = new StringBuffer();
        param.append(o.getOrderId()).append(IBlockService.SEPARATOR)
                .append(o.getId()).append(IBlockService.SEPARATOR)
                .append(o.getImage()==null || o.getImage().equals("") ? "": EncryptUtils.sha256(o.getImage())).append(IBlockService.SEPARATOR)
                .append(optionUserId);

        return param.toString();
    }
}
